#  This file is part of FlickFleck.
#  Copyright (C) 2008 Jyke Tapani Jokinen
#
#    FlickFleck is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FlickFleck is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with FlickFleck.  If not, see <http://www.gnu.org/licenses/>.
#
import Tkinter
import ui

# adhoc widget to make a progressbar
#
class Widget:

    def __init__(self, parent):
        self.w_parent = parent
        self.w_canvas = Tkinter.Canvas( parent )
        self.w_canvas.pack( fill='x', expand='yes')


    # called when the number of items in the whole operation is known
    def init(self, num_items):
        self.max = num_items
        self.clear()

    # called if starting again with the same max value
    def clear(self):
        self.count = 0
        self.w_canvas.delete(Tkinter.ALL)

    # draw one step forward in the progressbar (previously set max value used)
    def step(self):
        self.count = self.count + 1
        width = int( self.w_canvas['width'] )
        # if one_item_width < 1.0 it would go to zero with ints:
        one_item = float(width) / float(self.max)
        draw_width = one_item * self.count
        self.w_canvas.delete(Tkinter.ALL)
        self.w_canvas.create_rectangle(0,0,
                                       draw_width,ui.wins.PBheight,
                                       fill='blue')
        self.w_parent.update()
        
        
